/**
 *
 */
package com.storm.lib.vo;

import java.util.ArrayList;
import java.util.List;

import com.storm.lib.util.ArrayUtil;
import com.storm.lib.util.DBFieldUtil;
import com.storm.lib.util.ExceptionUtil;
import com.storm.lib.util.IntUtil;
import com.storm.lib.util.StringUtil;



/**
 * 类功能:
 * @author johnny
 * @version 2011-3-3
 */
public class IdNumberVo {

	/**
	 * 编号
	 */
	private Integer id;

	/**
	 * 数量
	 */
	private Integer num;



	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the num
	 */
	public Integer getNum() {
		return num;
	}

	/**
	 * @param num the num to set
	 */
	public void setNum(Integer num) {
		this.num = num;
	}

	/**
	 * 方法功能:得到List
	 * 更新时间:2011-2-24, 作者:johnny
	 * @param mailItems
	 * @return
	 */
	public static List<IdNumberVo> createList(String string) {
		List<IdNumberVo> itemNumbers= new ArrayList();
		if(StringUtil.isEmpty(string)){
			return itemNumbers;
		}
		String[] itemstrs =string.split(",");
		for (int i = 0; i < itemstrs.length; i++) {
			String[] vals = itemstrs[i].split("\\|");
			IdNumberVo itemNumberVo = new IdNumberVo();
			itemNumberVo.setId(DBFieldUtil.fetchImpodInt(vals[0]));
			itemNumberVo.setNum(DBFieldUtil.fetchImpodInt(vals[1]));
			itemNumbers.add(itemNumberVo);
		}
		return itemNumbers;
	}

	/**
	 * 方法功能:得到Str
	 * 更新时间:2011-2-24, 作者:johnny
	 * @param attachList
	 */
	public static String createStr(List<IdNumberVo> attachList,String innerSplit,String outterSplit) {
		String str=null;
		if(null==attachList || attachList.size()==0){
			return null;
		}
		String[] items = new String[attachList.size()];
		for (int i = 0; i < attachList.size(); i++) {
			IdNumberVo itemNumberVo = attachList.get(i);
			items[i]=itemNumberVo.getId()+innerSplit+itemNumberVo.getNum();
		}
		if(attachList.size()==0){
			return null;
		}
		else{
			return DBFieldUtil.implod(items, outterSplit);
		}
	}

	/**
	 * 方法功能:列表增加道具
	 * 更新时间:2011-3-18, 作者:johnny
	 * @param results
	 * @param itemId
	 * @param randomInt
	 */
	public static void addItemToList(List<IdNumberVo> results, int id,int num) {
		for (int i = 0; i < results.size(); i++) {
			IdNumberVo idNumberVo = results.get(i);
			if(idNumberVo.getId().intValue()==id){
				idNumberVo.setNum(idNumberVo.getNum()+num);
				return;
			}
		}
		IdNumberVo idNumberVo =new IdNumberVo();
		idNumberVo.setId(id);
		idNumberVo.setNum(num);
		results.add(idNumberVo);
	}

	/**
	 * 方法功能:列表增加道具
	 * 更新时间:2011-3-18, 作者:johnny
	 * @param results
	 * @param itemId
	 * @param randomInt
	 */
	public static void addItemToList(List<IdNumberVo> results,IdNumberVo idNumberVo) {
		if(results==null || idNumberVo==null){
			return;
		}
		for (int i = 0; i < results.size(); i++) {
			IdNumberVo idNumberVo2 = results.get(i);
			if(idNumberVo2.getId().intValue()==idNumberVo.getId()){
				idNumberVo2.setNum(idNumberVo2.getNum()+idNumberVo.getNum());
				return;
			}
		}
		IdNumberVo idNumberVo2 =new IdNumberVo();
		idNumberVo2.setId(idNumberVo.getId());
		idNumberVo2.setNum(idNumberVo.getNum());
		results.add(idNumberVo);
	}

	public IdNumberVo(Integer id, Integer num) {
		super();
		this.id = id;
		this.num = num;
	}

	public IdNumberVo() {
		super();
	}

	public static void addItemListToList(List<IdNumberVo> targetItems,List<IdNumberVo> addItems) {
		for (int i = 0; i < addItems.size(); i++) {
			addItemToList(targetItems, addItems.get(i));
		}
	}

	public static IdNumberVo create(String string) {
		if(StringUtil.isEmpty(string)){
			return null;
		}
		String[] vals = string.split("\\|");
		if(vals.length<=0){
			return null;
		}
		else{
			IdNumberVo idNumberVo = new IdNumberVo(Integer.valueOf(vals[0]),Integer.valueOf(vals[1]));
			return idNumberVo;
		}
	}
	
	public static List<IdNumberVo> createComplexList(String str){
		List<IdNumberVo> theIdnumberList = new ArrayList<IdNumberVo>();
		String[] monsterKills = str.split("@");
		for (String monsterKill : monsterKills) {
			String[] monSkillVals = monsterKill.split("\\|");
			Integer monsterId = Integer.valueOf(monSkillVals[0]);
			Integer num = Integer.valueOf(monSkillVals[1]);
			theIdnumberList.add(new IdNumberVo(monsterId, num));
		}
		return theIdnumberList;
	}
	
//	public static List<IdNumberVo> createEffectList(String str){
//		List<IdNumberVo> list = new ArrayList<IdNumberVo>();
//		String[] vals = str.split(",");
//		for (String string : vals) {
//			IdNumberVo idNumberVo = new IdNumberVo();
//			String[] items = string.split("\\|");
//			Integer type;
//			Integer number;
////			buffer_id:100001
////			hp:500
////			coin:200
////			point_know:100
//			if("buffer_id".equals(items[0])){
//				type=1;
//			}
//			else if("hp".equals(items[0])){
//				type=2;
//			}
//			else if("coin".equals(items[0])){
//				type=3;
//			}
//			else if("point_know".equals(items[0])){
//				type=4;
//			}			
//			else{
//				ExceptionUtil.throwInvalidParamException();
//			}
//			number = Integer.valueOf(items[1]);
//			list.add(idNumberVo);
//		}
//		return list;
//	}
}
